/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package managedBean.TX.tta;

import helper.tx.tta.Helper_IPCluster;
import java.util.ArrayList;
import java.util.List;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.model.SelectItem;
import session.TX.ItineraryPlannerSBRemote;

/**
 *
 * @author Lu Xiaodi
 */
@ManagedBean(name = "tCubePopularityMB")
@ViewScoped
public class TCubePopularityMB {

    @EJB
    private ItineraryPlannerSBRemote itineraryBean;
    private String[] countries;
    private String[] ageGroups;
    private String selectedCountry = "all";
    private String selectedAgeGroup = "all";

    /** Creates a new instance of TCubePopularityMB */
    public TCubePopularityMB() {
    }

    public List<Helper_IPCluster> getPopularity() {
        System.out.println("getting populatiry");
        System.out.println("SelectedCountry:" + selectedCountry);
        System.out.println("selectedAgeGroup:" + selectedAgeGroup);
        List<Helper_IPCluster> resultList = itineraryBean.getTop50Popular(selectedCountry, selectedAgeGroup);
        if (resultList == null){
            return null;
        }
        for (Helper_IPCluster result:resultList){
            System.out.println(result.getPopularity());
        }
        return resultList;
    }

    public List<SelectItem> getCountriesItems() {
        String[] c = getCountries();
        List<SelectItem> returnList = new ArrayList<SelectItem>();
        for (int i = 0; i < c.length; i++) {
            returnList.add(new SelectItem(c[i].trim(), c[i].trim()));
        }
        return returnList;
    }

    public List<SelectItem> getAgeGroupsItems() {
        String[] a = getAgeGroups();
        List<SelectItem> returnList = new ArrayList<SelectItem>();
        for (int i = 0; i < a.length; i++) {
            returnList.add(new SelectItem(a[i].trim(), a[i].trim()));
        }
        return returnList;
    }

    public String[] getCountries() {
        if (this.countries == null) {
            this.countries = itineraryBean.getCountriesList();
        }
        return countries;
    }

    public void setCountries(String[] countries) {
        this.countries = countries;
    }

    public String[] getAgeGroups() {
        if (this.ageGroups == null) {
            this.ageGroups = itineraryBean.getAgeGroupsList();
        }
        return ageGroups;
    }

    public void setAgeGroups(String[] ageGroups) {
        this.ageGroups = ageGroups;
    }

    public String getSelectedAgeGroup() {
        return selectedAgeGroup;
    }

    public void setSelectedAgeGroup(String selectedAgeGroup) {
        this.selectedAgeGroup = selectedAgeGroup;
    }

    public String getSelectedCountry() {
        return selectedCountry;
    }

    public void setSelectedCountry(String selectedCountry) {
        this.selectedCountry = selectedCountry;
    }
}
